"""
Configuration module for the Structural Text Analyzer.
Provides customizable settings for different analysis types.
"""

import os
from dataclasses import dataclass, field
from typing import Dict, List, Any, Optional

@dataclass
class AnalysisConfig:
    """Configuration class for structural analysis parameters."""
    
    # File processing
    max_file_size_mb: int = 100
    encoding: str = 'utf-8'
    chunk_size: int = 8192
    
    # Text analysis
    min_sentence_length: int = 3
    max_sentence_length: int = 1000
    language: str = 'en'
    
    # Numerical analysis
    scientific_notation_threshold: float = 1e6
    large_number_threshold: float = 1e10
    small_number_threshold: float = 1e-10
    convergence_tolerance: float = 1e-6
    stagnation_variance_threshold: float = 1e-8
    
    # Trend analysis
    min_sequence_length: int = 3
    trend_smoothing_window: int = 5
    convergence_rate_window: int = 10
    
    # Anomaly detection
    detect_nan: bool = True
    detect_inf: bool = True
    detect_zero_division: bool = True
    detect_large_numbers: bool = True
    
    # Output configuration
    generate_plots: bool = True  # Enable for text descriptions
    output_format: str = 'markdown'  # 'markdown', 'json', 'txt'
    include_raw_data: bool = False
    generate_text_descriptions: bool = True
    
    # Visualization
    plot_dpi: int = 300
    plot_style: str = 'seaborn-v0_8'
    figure_size: tuple = (12, 8)
    
class ConfigManager:
    """Manages configuration for different text types and use cases."""
    
    @staticmethod
    def get_config_for_type(text_type: str) -> AnalysisConfig:
        """Get pre-configured settings for different text types."""
        
        configs = {
            'computational_log': AnalysisConfig(
                scientific_notation_threshold=1e3,
                large_number_threshold=1e8,
                convergence_tolerance=1e-8,
                trend_smoothing_window=3,
                min_sequence_length=5
            ),
            
            'academic_paper': AnalysisConfig(
                min_sentence_length=10,
                max_sentence_length=500,
                detect_large_numbers=False,
                generate_plots=False
            ),
            
            'social_text': AnalysisConfig(
                min_sentence_length=1,
                max_sentence_length=280,
                detect_nan=False,
                detect_inf=False,
                scientific_notation_threshold=1e12
            ),
            
            'default': AnalysisConfig()
        }
        
        return configs.get(text_type.lower(), configs['default'])
    
    @staticmethod
    def create_custom_config(**kwargs) -> AnalysisConfig:
        """Create a custom configuration with specified parameters."""
        config = AnalysisConfig()
        for key, value in kwargs.items():
            if hasattr(config, key):
                setattr(config, key, value)
        return config
